/*
 * Define SimpleOrderPanel Class
 */
SimpleOrderPanel = function(){
    this.basicInfoPanel = new BasicInfoPanel();
    this.senderPanel = new SenderPanel();
    this.recipientPanel = new RecipientPanel();
    this.extraInfoPanel = new ExtraInfoPanel();
    this.addressInfoPanel = new Ext.Panel({
        autoHeight: true,
        layout: "column",
        items: [this.senderPanel, this.recipientPanel]
    });
    this.soItemsPanel = new SoItemsPanel();
    
    SimpleOrderPanel.superclass.constructor.call(this, {
        id: "orderPanel",
        width: 840,
        autoHeight: true,
        fileUpload: true,
        items: [this.basicInfoPanel, this.addressInfoPanel, this.extraInfoPanel, this.soItemsPanel],
        buttons: [{
            xtype: "button",
            text: "完成",
            scope: this,
            handler: this.finishOrder
        }, {
            xtype: "button",
            text: "完成并提交",
            scope: this,
            handler: this.submitOrder
        }],
        buttonAlign: "left",
        listeners: {
            afterrender: function(){
                Ext.select(".requiredlabel").insertHtml("beforeEnd", "<span style='color:red'>*</span>");
            }
        }
    });
}
Ext.extend(SimpleOrderPanel, Ext.form.FormPanel, {
    submitOrder: function(){
        this.finishOrder(true);
    },
    
    finishOrder: function(submit){
    
        if (!this.validateOrder()) {
            return;
        }
        var formdata = Ext.getCmp("orderPanel").getForm().getValues();
        var mask = new Ext.LoadMask(Ext.getBody(), {
            msg: "数据正在处理中，请稍等..."
        });
        
        var items = new Array();
        var records = Ext.getCmp("soiPanel").getStore().getRange();
        for (var i = 0; i < records.length; i++) {
            items.push(records[i].data);
        }
        
        formdata.itemsJson = Ext.encode(items);
        formdata.submit = submit;
        
        mask.show();
        
        Ext.Ajax.request({
            url: "../../popup/extjs/SubmitSimpleOrder.bl",
            params: formdata,
            scope: this,
            success: function(response, options){
                mask.hide();
                Ext.getCmp("orderPanel").disable();
                var data = Ext.util.JSON.decode(response.responseText);
                Ext.MessageBox.show({
                    title: '提示',
                    msg: "订单创建成功：" + data.orderNumber + ", 要上传附件吗？点[是]上传，点[否]继续录单，点[取消]回到订单列表页面",
                    buttons: Ext.MessageBox.YESNOCANCEL,
                    closed: false,
                    fn: function(btn, text){
                        if (btn == "yes") {
                            var popup = PopupManager.getFileuploadWindow(data.orderNumber);
                        }
                        else 
                            if (btn == "no") {
                                window.location.reload();
                            }
                            else 
                                if (btn == "cancel") {
                                    window.location.href = "ListOrder.bl";
                                }
                    },
                    animEl: 'mb4',
                    icon: Ext.MessageBox.QUESTION
                });
            },
            failure: function(){
                mask.hide();
                Ext.Msg.alert("提示", "订单创建失败!");
            }
        });
    },
    
    validateOrder: function(){
        if (!Ext.getCmp("orderPanel").getForm().isValid()) {
            return false;
        }
        
        var pickupTime = Ext.getCmp("pickupDateBegain").getValue();
        var deliveryTime = Ext.getCmp("deliveryDateEnd").getValue();
        if (pickupTime >= deliveryTime) {
            Ext.Msg.alert("提示", "送货时间必须晚于提货时间");
            return false;
        }
        
        var soiPanel = Ext.getCmp("soiPanel");
        var count = soiPanel.dataStore.getCount();
        if (count == 0) {
            Ext.Msg.alert("提示", "订单项信息不能为空");
            return false;
        }
        
        return true;
    }
});

/*
 * Define BasicInfoPanel Class
 */
BasicInfoPanel = function(){
    var customerStore = StoreManager.getCustomerStore();
    this.billToPartyStore.on("load", this.onBillToPartyStoreLoad);
    BasicInfoPanel.superclass.constructor.call(this, {
        title: "订单基本信息",
        autoHeight: true,
        frame: true,
        id: "basicorderPanel",
        layout: "table",
        layoutConfig: {
            columns: 6
        },
        bodyStyle: "line-height: 26px",
        items: [{
            xtype: "label",
            text: "业务类型：",
            cls: "formlabel"
        }, {
            xtype: "radiogroup",
            width: 190,
            ctCls: "formfield",
            items: [{
                boxLabel: "零担",
                name: "order.serviceType",
                checked: true,
                inputValue: "LTL",
                listeners: {
                    check: function(radio, checked){
                        if (checked) {
                            Ext.get("vehicleTypeCategoryLabel").child("span").remove();
                            var vehicleTypeCategoryCmp = Ext.getCmp("vehicleTypeCategory");
                            vehicleTypeCategoryCmp.allowBlank = true;
                            vehicleTypeCategoryCmp.clearInvalid();
                            
                            Ext.get("vehicleTypeLabel").child("span").remove();
                            var vehicleTypeCmp = Ext.getCmp("vehicleTypeName");
                            vehicleTypeCmp.allowBlank = true;
                            vehicleTypeCmp.clearInvalid();
                            
                            Ext.get("routeLabel").child("span").remove();
                            var routeNameCmp = Ext.getCmp("routeName");
                            routeNameCmp.allowBlank = true;
                            routeNameCmp.clearInvalid();
                        }
                        else {
                            Ext.get("vehicleTypeCategoryLabel").insertHtml("beforeEnd", "<span style='color:red'>*</span>");
                            Ext.getCmp("vehicleTypeCategory").allowBlank = false;
                            
                            Ext.get("vehicleTypeLabel").insertHtml("beforeEnd", "<span style='color:red'>*</span>");
                            Ext.getCmp("vehicleTypeName").allowBlank = false;
                            
                            Ext.get("routeLabel").insertHtml("beforeEnd", "<span style='color:red'>*</span>");
                            Ext.getCmp("routeName").allowBlank = false;
                        }
                    }
                }
            }, {
                boxLabel: "整车",
                name: "order.serviceType",
                inputValue: "FTL"
            }]
        }, {
            xtype: "label",
            text: "客户：",
            cls: "formlabel requiredlabel"
        }, {
            xtype: "popupcombo",
            id: "customer",
            name: "customer",
            store: customerStore,
            queryParam: "keyword",
            mode: "remote",
            editable: true,
            allowBlank: false,
            pageSize:10,
            displayField: "name",
            valueField: "id",
            triggerAction: "query",
            listWidth: 280,
            emptyText: "-请选择-",
            ctCls: "formfield",
            width: 190,
            popupWindow: function(){
                var popup = PopupManager.getCustomerPopup(function(record){
                    Ext.getCmp("basicorderPanel").fillCustomerPro(record);
                    Ext.getCmp("customer").fireEvent('select', this, record);
                });
                this.popup = popup;
            },
            listeners: {
                select: this.onCustomerSelect
            }
        }, {
            xtype: "label",
            text: "结算方：",
            cls: "formlabel requiredlabel"
        }, {
            xtype: "combo",
            id: "billToParty",
            fieldLabel: "结算方",
            valueField: "id",
            editable: false,
            displayField: "name",
            store: this.billToPartyStore,
            mode: "local",
            triggerAction: "all",
            emptyText: "-请先选择客户-",
            selectOnFocus: true,
            forceSelection: true,
            disabled: true,
            width: 190,
            ctCls: "formfield",
            listeners: {
                change: function(field, newValue, oldValue){
                    // 测试多结算方的选择
                    Ext.getCmp("billToPartyId").setValue(this.getValue());
                }
            }
        }, // new row
        {
            xtype: "label",
            text: "代购保险：",
            cls: "formlabel"
        }, {
            xtype: "checkbox",
            id: "insured",
            name: "order.insured",
            boxLabel: " ",
            width: 190,
            inputValue: "true",
            ctCls: "formfield",
            disabled: true,
            listeners: {
                check: this.onInsuredCheck
            }
        }, {
            xtype: "label",
            text: "投保金额：",
            id: "insuredMoneyLabel",
            cls: "formlabel"
        }, {
            xtype: "numberfield",
            id: "insuredMoney",
            name: "order.insuredMoney",
            allowBlank: false,
            width: 190,
            ctCls: "formfield",
            disabled: true,
            listeners: {
                change: this.onInsuredMoneyChange
            }
        }, {
            xtype: "label",
            text: "保险费：",
            id: "insuranceLabel",
            cls: "formlabel"
        }, {
            xtype: "numberfield",
            id: "insurance",
            name: "order.insurance",
            allowBlank: false,
            width: 190,
            ctCls: "formfield",
            disabled: true
        }, // new row
        {
            xtype: "label",
            text: "参考单号：",
            cls: "formlabel"
        }, {
            xtype: "textfield",
            name: "order.refNumber",
            width: 190,
            ctCls: "formfield"
        }, {
            xtype: "label",
            text: "客户单号：",
            cls: "formlabel"
        }, {
            xtype: "textfield",
            name: "order.bizOrderNumber",
            width: 190,
            ctCls: "formfield"
        }, {
            xtype: "label",
            text: "托运单号：",
            cls: "formlabel"
        }, {
            xtype: "textfield",
            name: "order.refNumber1",
            width: 190,
            ctCls: "formfield"
        }, {
            xtype: "label",
            text: "回程单号：",
            cls: "formlabel"
        }, {
            xtype: "textfield",
            name: "order.backHaulSONumber",
            width: 190,
            ctCls: "formfield",
            validationEvent: "blur",
            validFlag: false,
            validator: function(){
                if (this.getValue() == "") {
                    return true;
                }
                Ext.Ajax.request({
                    url: "../../popup/extjs/CheckBackHaulSoNumber.bl",
                    params: {
                        soNumber: this.getValue()
                    },
                    scope: this,
                    success: function(response, options){
                        var data = Ext.util.JSON.decode(response.responseText);
                        if (data.validBackHaulSoNumber) {
                            this.validFlag = true;
                            this.clearInvalid();
                        }
                        else {
                            this.validFlag = false;
                            this.markInvalid("请输入正确的回程单号");
                        }
                    }
                });
                return this.validFlag;
            }
        }, {
            xtype: "label",
            text: "备注：",
            cls: "formlabel"
        }, {
            xtype: "textfield",
            name: "order.desc",
            width: 190,
            ctCls: "formfield"
        }, {
            xtype: "label",
            text: "完全卖单：",
            cls: "formlabel"
        }, {
            xtype: "checkbox",
            id: "wholeSaled",
            name: "order.wholeSelled",
            boxLabel: " ",
            width: 190,
            inputValue: "true",
            ctCls: "formfield"
        }, {
            xtype: "label",
            text: "要求回单日期：",
            cls: "formlabel"
        }, {
            xtype: "textfield",
            id: "podRequestTime",
            name: "order.podRequestTime",
            width: 130,
            readOnly: true
        }, {
            xtype: "label",
            text: "接单时间：",
            cls: "formlabel requiredlabel"
        }, {
            xtype: "datefield",
            vtype: "daterange",
            allowBlank: false,
            format: "Y-m-d H:i",
            id: "orderInputTime",
            name: "order.orderInputTime",
            width: 130,
            listeners: {
                afterrender: function(){
                    var now = new Date();
                    Ext.getCmp("orderInputTime").setValue(now.format("Y-m-d H:i"));
                }
            }
        }, {
            xtype: "label",
            text: "回单条码：",
            cls: "formlabel"
        }, {
            xtype: "trigger",
            id: "scanCode",
            name: "order.scanCode",
            editable: false,
            width: 130,
            onTriggerClick: function(){
                popupBarCodeWin(Ext.getCmp('scanCode').getValue());
            }
            
        }, // hidden value here
        {
            items: [{
                xtype: "hidden",
                id: "customerId",
                name: "order.customer.id"
            }, {
                xtype: "hidden",
                id: "billToPartyId",
                name: "order.billToParty.id"
            }, {
                xtype: "hidden",
                id: "insuredRate",
                name: "order.insuredRate"
            }, {
                xtype: "hidden",
                id: "settlementtype"
            }, {
                xtype: "hidden",
                id: "timelimit"
            }]
        }]
    });
}

Ext.extend(BasicInfoPanel, Ext.Panel, {
    billToPartyStore: StoreManager.getBillToPartyStore(),
    
    fillCustomerPro: function(record){
        Ext.getCmp("customerId").setValue(record.id);
        Ext.getCmp("customer").setValue(record.name);
        if (record.customerProfile != null) {
            //填充客户profile
            Ext.getCmp("specialRequirement").setValue(record.customerProfile.specialRequirement);
            Ext.getCmp("wholeSaled").setValue(record.customerProfile.wholeSaled);
            //填充计费方式
            var settlementtype = record.customerProfile.settlementMethod;
            //todo 填充订单属性
            Ext.getCmp("orderProperties").setValue(record.customerProfile.projectStyle);
            Ext.get("orderProShow").child("span").remove();
            Ext.get("orderProShow").insertHtml('beforeEnd', '<span>' + (record.customerProfile.projectStyle || '') + '</span>');
            var settlementtype_zh;
            switch (settlementtype) {
                case 'WEIGHT':
                    settlementtype_zh = "客户按重量计费";
                    break;
                case 'VOLUME':
                    settlementtype_zh = "客户按体积计费";
                    break;
                case 'AMOUNT':
                    settlementtype_zh = "客户按数量计费";
                    break;
                case 'STANDARD':
                    settlementtype_zh = "客户按标准计费";
            }
            Ext.getCmp("saleOrderWeightnessLevel").setValue(record.weightnessLevel);
            Ext.getCmp("settlementtype").setValue(settlementtype_zh);
        }
        else {
            Ext.getCmp("orderProperties").setValue("");
            Ext.get("orderProShow").child("span").remove();
            Ext.get("orderProShow").insertHtml('beforeEnd', '<span></span>');
        }
    },
    
    onCustomerSelect: function(combo, record, index){
        Ext.getCmp("basicorderPanel").fillCustomerPro(record.data ? record.data : record);
        Ext.getCmp('basicorderPanel').onCustomerChange();
    },
    
    onCustomerChange: function(field, newValue, oldValue){
        var soiPanel = Ext.getCmp("soiPanel");
        soiPanel.store.removeAll(false);
        soiPanel.defaultFreight = null;
        soiPanel.defaultPacking = null;
        
        var customerId = Ext.getCmp("customerId").getValue();
        var customerField = Ext.getCmp("customer");
        var customerData = customerField.popup ? customerField.popup.store.getById(customerId).data : customerField.getStore().getById(customerId).data;
        
        // set default billToParty
        var billToParty = Ext.getCmp("billToParty");
        billToParty.clearValue();
        billToParty.store.baseParams = {
            customerId: customerId
        };
        billToParty.store.reload();
        billToParty.enable();
        
        // set customer related insured rate
        var insuredField = Ext.getCmp("insured");
        insuredField.enable();
        insuredField.setValue(customerData.insured);
        Ext.getCmp("insuredMoney").setValue("");
        Ext.getCmp("insurance").setValue("");
        if (customerData.insured) {
            Ext.getCmp("insuredMoney").enable();
            Ext.getCmp("insurance").enable();
        }
        
        Ext.getCmp("insuredRate").setValue(customerData.insuredRate);
        
        Ext.Ajax.request({
            url: "../../popup/extjs/DefaultSenderAndReceiverJson.bl",
            params: {
                customerId: customerId
            },
            scope: this,
            success: function(response, options){
                var data = Ext.decode(response.responseText);
                Ext.getCmp("podRequestTime").setValue(null);
                Ext.getCmp("sender").enable();
                var sender = data.sender;
                if (sender) {
                    Ext.getCmp("senderId").setValue(sender.id);
                    Ext.getCmp("senderCode").setValue(sender.code);
                    Ext.getCmp("sender").enable().setValue(sender.name);
                    Ext.getCmp("needPickupAppointment").setValue(sender.needReservation);
                    if (sender.defaultAddress) {
                        if (sender.defaultAddress.naturalZoneVO.selectable) {
                            Ext.getCmp("senderAddressZoneName").validFlag = true;
                        }
                        else {
                            Ext.getCmp("senderAddressZoneName").validFlag = false;
                        }
                        Ext.getCmp("senderAddressZoneId").setValue(sender.defaultAddress.naturalZoneVO.id);
                        Ext.getCmp("senderAddressZoneName").setValue(sender.defaultAddress.area);
                        Ext.getCmp("senderAddressZoneName").fireEvent("change");
                        Ext.getCmp("senderAddressDetailShow").setValue(sender.defaultAddress.area + sender.defaultAddress.street);
                        Ext.getCmp("senderAddressDetail").setValue(sender.defaultAddress.street);
                        Ext.getCmp("senderContactPerson").setValue(sender.defaultAddress.contactPersonName);
                        Ext.getCmp("senderContactPhone").setValue(sender.defaultAddress.contactPhone);
                    }
                }
                else {
                	Ext.getCmp("senderId").setValue(null);
                    Ext.getCmp("senderCode").setValue(null);
                    Ext.getCmp("sender").enable().setValue(null);
                    Ext.getCmp("needPickupAppointment").setValue(null);
                    Ext.getCmp("senderAddressZoneName").validFlag = true;
                    Ext.getCmp("senderAddressZoneId").setValue(null);
                    Ext.getCmp("senderAddressZoneName").setValue(null);
                    Ext.getCmp("senderAddressDetailShow").setValue(null);
                    Ext.getCmp("senderAddressDetail").setValue(null);
                    Ext.getCmp("senderContactPerson").setValue(null);
                    Ext.getCmp("senderContactPhone").setValue(null);
                    Ext.getCmp("podRequestTime").setValue(null);
                    Ext.getCmp("senderAddressZoneName").fireEvent("change");
                }
                
                Ext.getCmp("recipient").enable();
                var recipient = data.receiver;
                if (recipient) {
                    Ext.getCmp("recipientId").setValue(recipient.id);
                    Ext.getCmp("recipientCode").setValue(recipient.code);
                    Ext.getCmp("recipient").setValue(recipient.name);
                    Ext.getCmp("needDeliveryAppointment").setValue(recipient.needReservation);
                    if (recipient.defaultAddress) {
                        if (recipient.defaultAddress.naturalZoneVO.selectable) {
                            Ext.getCmp("recipientAddressZoneName").validFlag = true;
                        }
                        else {
                            Ext.getCmp("recipientAddressZoneName").validFlag = false;
                        }
                        Ext.getCmp("recipientAddressZoneId").setValue(recipient.defaultAddress.naturalZoneVO.id);
                        Ext.getCmp("recipientAddressZoneName").setValue(recipient.defaultAddress.area);
                        Ext.getCmp("recipientAddressZoneName").fireEvent("change");
                        Ext.getCmp("recipientAddressDetailShow").setValue(recipient.defaultAddress.area + recipient.defaultAddress.street);
                        Ext.getCmp("recipientAddressDetail").setValue(recipient.defaultAddress.street);
                        Ext.getCmp("recipientContactPerson").setValue(recipient.defaultAddress.contactPersonName);
                        Ext.getCmp("recipientContactPhone").setValue(recipient.defaultAddress.contactPhone);
                    }
                }
                else {
                	Ext.getCmp("recipientId").setValue(null);
                    Ext.getCmp("recipientCode").setValue(null);
                    Ext.getCmp("recipient").setValue(null);
                    Ext.getCmp("needDeliveryAppointment").setValue(null);
                    Ext.getCmp("recipientAddressZoneName").validFlag = true;
                    Ext.getCmp("recipientAddressZoneId").setValue(null);
                    Ext.getCmp("recipientAddressZoneName").setValue(null);
                    Ext.getCmp("recipientAddressDetailShow").setValue(null);
                    Ext.getCmp("recipientAddressDetail").setValue(null);
                    Ext.getCmp("recipientContactPerson").setValue(null);
                    Ext.getCmp("recipientContactPhone").setValue(null);
                    Ext.getCmp("recipientAddressZoneName").fireEvent("change");
                }
            }
        });
        
        var fstore = Ext.getCmp("soiPanel").freightStore;
        fstore.baseParams = {
            customerId: customerId
        };
        fstore.reload();
        
        var bastore = Ext.getCmp("soiPanel").bizAssociatedStore;
        bastore.baseParams = {
            associatedPartyType: "BIZASSOCIATED",
            customerId: customerId
        };
        bastore.reload();
        
        fstore.on("load", function(store, records, options){
            if (records.length > 0) {
                var defaultFreight = records[0].data;
                if (!soiPanel.defaultFreight) {
                    soiPanel.defaultFreight = defaultFreight;
                }
                soiPanel.packingStore.baseParams = {
                    freightId: defaultFreight.id,
                    setDefaultPacking: true
                };
                soiPanel.packingStore.reload();
                soiPanel.enable();
            }
            
        });
        
        var senderStore = Ext.getCmp("sender").store;
        senderStore.baseParams = {
            customerId: customerId,
            type: "SENDER"
        }
        
        var recipientStroe = Ext.getCmp("recipient").store;
        recipientStroe.baseParams = {
            customerId: customerId,
            type: "RECEIVER"
        }
    },
    
    onBillToPartyStoreLoad: function(store, records, options){
        var defVal = records[0].data;
        for (var idx = 0; idx < records.length; idx++) {
            if (records[idx].data.byDefault) {
                defVal = records[idx].data;
            }
        }
        var billToParty = Ext.getCmp("billToParty");
        billToParty.setValue(defVal.id);
        Ext.getCmp("billToPartyId").setValue(defVal.id);
    },
    
    onInsuredCheck: function(checkbox, checked){
        var insuredMoneyCmp = Ext.getCmp("insuredMoney");
        
        var insuranceCmp = Ext.getCmp("insurance");
        var insuredMoneyLabel = Ext.get("insuredMoneyLabel");
        var insuranceLabel = Ext.get("insuranceLabel");
        if (checked) {
            insuredMoneyCmp.enable();
            insuredMoneyLabel.insertHtml("beforeEnd", "<span style='color:red'>*</span>");
            
            insuranceCmp.enable();
            insuranceLabel.insertHtml("beforeEnd", "<span style='color:red'>*</span>");
        }
        else {
            insuredMoneyCmp.disable();
            insuredMoneyCmp.clearInvalid();
            insuredMoneyCmp.setValue("");
            insuredMoneyLabel.child("span").remove();
            
            insuranceCmp.disable();
            insuranceCmp.setValue("");
            insuranceCmp.clearInvalid();
            insuranceLabel.child("span").remove();
        }
    },
    
    onInsuredMoneyChange: function(field, newValue, oldValue){
    
        var insuredRate = Ext.getCmp("insuredRate").getValue();
        Ext.getCmp("insurance").setValue(insuredRate * newValue);
    }
});

/*
 * Define SenderPanel Class
 */
SenderPanel = function(){
    SenderPanel.superclass.constructor.call(this, {
        id: "senderPanel",
        title: "发货方信息",
        frame: true,
        columnWidth: .5,
        height:195,
        layout: "table",
        layoutConfig: {
            columns: 6
        },
        bodyStyle: "line-height: 26px",
        items: [{
            xtype: "label",
            text: "发货方：",
            width: 190,
            cls: "requiredlabel"
        }, {
            colspan: 4,
            xtype: "popupcombo",
            id: "sender",
            name: "order.senderName",
            store: StoreManager.getLogicAddressIncreSearchStore(),
            width: 190,
            editable: true,
            displayField: "name",
            valueField: "id",
            queryParam: "keyword",
            disabled: true,
            triggerAction: "query",
            allowBlank: false,
            emptyText: "-请先选择客户-",
            popupWindow: function(){
                var customerId = Ext.getCmp("customerId").getValue();
                var params = {
                    customerId: customerId,
                    type: "SENDER"
                };
                var title = "发货方";
                var popup = PopupManager.getLogicAddressPopup(title, params, function(sender){
                    Ext.getCmp("senderPanel").fillSendPro(sender);
                });
            },
            listeners: {
                select: this.onSenderSelect
            }
        }, {
            items: [{
                xtype: "hidden",
                id: "senderId",
                name: "order.senderId"
            }, {
                xtype: "hidden",
                id: "senderCode",
                name: "order.senderCode"
            }]
        }, {
            xtype: "label",
            text: "上门提货："
        }, {
            xtype: "checkbox",
            name: "order.needPickup",
            boxLabel: " ",
            checked: true,
            inputValue: "true",
            listeners: {
                check: function(checkbox, checked){
                    if (checked) {
                        Ext.select(".sender-add1").addClass("nodisplay");
                        Ext.getCmp("senderPosId").disable();
                        Ext.getCmp("senderPosName").disable();
                        Ext.getCmp("senderAddressZoneName").enable();
                        Ext.select(".sender-add2").removeClass("nodisplay");
                        Ext.getCmp("senderAddressZoneId").enable();
                        Ext.getCmp("senderAddressDetailShow").enable();
                    }
                    else {
                        Ext.select(".sender-add1").removeClass("nodisplay");
                        Ext.getCmp("senderPosId").enable();
                        Ext.getCmp("senderPosName").enable();
                        Ext.getCmp("senderAddressZoneName").disable();
                        Ext.select(".sender-add2").addClass("nodisplay");
                        Ext.getCmp("senderAddressZoneId").disable();
                        Ext.getCmp("senderAddressDetailShow").disable();
                    };
                                    }
            }
        }, {
            xtype: "label",
            text: "装载服务："
        }, {
            xtype: "checkbox",
            name: "order.needLoad",
            boxLabel: " ",
            inputValue: "true"
        }, {
            xtype: "label",
            text: "提货预约："
        }, {
            xtype: "checkbox",
            id: "needPickupAppointment",
            name: "order.needPickupAppointment",
            inputValue: "true",
            boxLabel: " "
        }, {
            xtype: "label",
            text: "物流节点：",
            ctCls: "sender-add1 nodisplay",
            cls: "requiredlabel"
        }, {
            colspan: 4,
            xtype: "popupfield",
            id: "senderPosName",
            editable: false,
            allowBlank: true,
            width: 190,
            ctCls: "sender-add1 nodisplay",
            popupWindow: function(){
                var popup = PopupManager.getPosPopup(function(r){
                    Ext.getCmp("senderPosId").setValue(r.id);
                    Ext.getCmp("senderPosName").setValue(r.name);
                });
            }
        }, {
            xtype: "hidden",
            id: "senderPosId",
            name: "order.senderPOS.id",
            ctCls: "sender-add1 nodisplay",
            disabled: true
        }, {
            xtype: "label",
            text: "详细地址：",
            ctCls: "sender-add2",
            cls: "requiredlabel"
        }, {
            colspan: 5,
            xtype: "popupfield",
            id: "senderAddressDetailShow",
            allowBlank: false,
            width: 250,
            ctCls: "sender-add2",
            popupWindow: function(){
                var senderCode = Ext.getCmp("senderCode").getValue();
                if (!senderCode) {
                    Ext.Msg.alert("提示", "请先选择发货方");
                    return;
                }
                var params = {
                    groupCode: senderCode
                };
                var popup = PopupManager.getAddressPopup(params, function(r){
                    Ext.getCmp("senderAddressZoneId").setValue(r.nzoneId);
                    Ext.getCmp("senderAddressZoneName").validFlag = r.selectable;
                    Ext.getCmp("senderAddressZoneName").setValue(r.area);
                    Ext.getCmp("senderAddressZoneName").fireEvent("change");
                    Ext.getCmp("senderAddressDetailShow").setValue(r.area + r.street);
                    Ext.getCmp("senderAddressDetail").setValue(r.street);
                });
            },
            listeners: {
                blur: function(){
                    var address = Ext.getCmp("senderAddressDetailShow").getValue();
                    Ext.Ajax.request({
                        url: "../../module/naturalZone/AddressParseJson.bl",
                        params: {
                            addresses: address
                        },
                        scope: this,
                        success: function(response, options){
                            var data = Ext.util.JSON.decode(response.responseText).resultList[0];
                            if (data.naturalZoneVO != null) {
                                //如果区域有报价
                                if (data.naturalZoneVO.selectable) {
                                    Ext.getCmp("senderAddressZoneName").clearInvalid();
                                    Ext.getCmp("senderAddressZoneId").setValue(data.naturalZoneVO.id);
                                    Ext.getCmp("senderAddressZoneName").validFlag = true;
                                    Ext.getCmp("senderAddressZoneName").fireEvent("change");
                                }
                                else {
                                    Ext.getCmp("senderAddressZoneName").markInvalid("区域无报价!");
                                    Ext.getCmp("senderAddressZoneName").validFlag = false;
                                }
                                var address = data.naturalZoneVO.namePath.replace(/\|/g, " ");
                                var addressdetail = address + data.street;
                                Ext.getCmp("senderAddressZoneName").setValue(address);
                                //详细地址显示区域+详细街道地址
                                Ext.getCmp("senderAddressDetailShow").setValue(addressdetail);
                                Ext.getCmp("senderAddressDetail").setValue(data.street);
                            }
                        }
                    });
                }
            }
        }, {
            xtype: "label",
            text: "提货区域：",
            ctCls: "sender-add2",
            cls: "requiredlabel"
        }, {
            colspan: 4,
            xtype: "nzonefield",
            id: "senderAddressZoneName",
            editable: false,
            allowBlank: false,
            width: 190,
            ctCls: "sender-add2",
            validFlag: false,
            popupWindow: function(){
                Geni.Popup.showWindow({
                    url: "../../module/naturalZone/ZoneSelectable.bl",
                    title: '选择区域',
                    width: 300,
                    height: 400,
                    returnCallback: function(data){
                        Ext.getCmp("senderAddressZoneId").setValue(data.key);
                        Ext.getCmp("senderAddressZoneName").validFlag = true;
                        Ext.getCmp("senderAddressZoneName").setValue(data.value);
                        Ext.getCmp("senderAddressZoneName").fireEvent("change");
                    }
                });
            },
            listeners: {
                change: function(){
                    var nzoneId = Ext.getCmp("senderAddressZoneId").getValue();
                    Ext.Ajax.request({
                        url: "../../popup/extjs/DefaultOrgJson.bl",
                        params: {
                            nZoneId: nzoneId
                        },
                        scope: this,
                        success: function(response, options){
                            var data = Ext.util.JSON.decode(response.responseText);
                            // Ext.getCmp("opOrgName").enable();
                            Ext.getCmp("opOrgId").setValue(data.organization.id);
                            Ext.getCmp("opOrgName").setValue(data.organization.name);
                        }
                    });
                    StoreManager.calcPodTime(Ext.getCmp('pickupDateBegain').getValue());
                }
            },
            validator: function(){
                return this.validFlag;
            }
        }, {
            items: [{
                xtype: "hidden",
                id: "senderAddressDetail",
                name: "order.senderAddressDetail"
            }, {
                xtype: "hidden",
                id: "senderAddressZoneId",
                name: "order.senderAddressZone.id",
                ctCls: "recipient-add2"
            }]
        }, {
            xtype: "label",
            text: "联系人："
        }, {
            xtype: "textfield",
            id: "senderContactPerson",
            name: "order.senderContactPersonName",
            width: 120
        }, {
            xtype: "label",
            text: "联系电话：",
            width: 30
        }, {
            xtype: "textfield",
            id: "senderContactPhone",
            name: "order.senderContactPhone",
            width: 120,
            colspan: 3
        }, {
            xtype: "label",
            text: "提货时间段：",
            cls: "requiredlabel"
        }, {
            xtype: "datefield",
            vtype: "daterange",
            id: "pickupDateBegain",
            name: "order.preferredPickupTimeDateBegain",
            allowBlank: false,
            format: "Y-m-d H:i",
            width: 130,
            //endDateField: "pickupDateEnd",
            listeners: {
                blur: function(){
                    if (Ext.getCmp("pickupDateEnd").getValue() == null || Ext.getCmp("pickupDateEnd").getValue() == "") {
                        Ext.getCmp("pickupDateEnd").setValue(Ext.getCmp("pickupDateBegain").getValue());
                    }
                    StoreManager.calcPodTime(Ext.getCmp('pickupDateBegain').getValue());
                }
            }
        }, {
            xtype: "label",
            text: "~"
        }, {
            xtype: "datefield",
            vtype: "daterange",
            id: "pickupDateEnd",
            name: "order.preferredPickupTimeDateEnd",
            allowBlank: false,
            format: "Y-m-d H:i",
            startDateField: "pickupDateBegain",
            width: 130,
            endDateField: "deliveryDateBegain",
            colspan: 3
        }]
    });
}

Ext.extend(SenderPanel, Ext.Panel, {
    onSenderSelect: function(combo, record, index){
        Ext.getCmp('senderPanel').fillSendPro(record.data);
    },
    
    fillSendPro: function(sender){
        Ext.getCmp("senderId").setValue(sender.id);
        Ext.getCmp("senderCode").setValue(sender.code);
        Ext.getCmp("sender").setValue(sender.name);
        Ext.getCmp("needPickupAppointment").setValue(sender.needReservation);
        if (sender.defaultAddress) {
            Ext.getCmp("senderAddressZoneId").setValue(sender.defaultAddress.naturalZoneVO.id);
            Ext.getCmp("senderAddressZoneName").validFlag = sender.defaultAddress.naturalZoneVO.selectable;
            Ext.getCmp("senderAddressZoneName").setValue(sender.defaultAddress.area);
            Ext.getCmp("senderAddressZoneName").fireEvent("change");
            
            Ext.getCmp("senderAddressDetailShow").setValue(sender.defaultAddress.area + sender.defaultAddress.street);
            Ext.getCmp("senderAddressDetail").setValue(sender.defaultAddress.street);
            Ext.getCmp("senderContactPerson").setValue(sender.defaultAddress.contactPersonName);
            Ext.getCmp("senderContactPhone").setValue(sender.defaultAddress.contactPhone);
        }
    }
});

/*
 * Define RecipientPanel Class
 */
RecipientPanel = function(){
    RecipientPanel.superclass.constructor.call(this, {
        id: "recipientPanel",
        title: "收货方信息",
        frame: true,
        columnWidth: .5,
        height:195,
        layout: "table",
        layoutConfig: {
            columns: 6
        },
        bodyStyle: "line-height: 26px",
        items: [{
            xtype: "label",
            text: "收货方：",
            width: 30,
            cls: "requiredlabel"
        }, {
            colspan: 4,
            xtype: "popupcombo",
            id: "recipient",
            name: "order.recipientName",
            width: 190,
            editable: false,
            store: StoreManager.getLogicAddressIncreSearchStore(),
            width: 190,
            editable: true,
            displayField: "name",
            valueField: "id",
            queryParam: "keyword",
            disabled: true,
            triggerAction: "query",
            allowBlank: false,
            emptyText: "-请先选择客户-",
            popupWindow: function(){
                var customerId = Ext.getCmp("customerId").getValue();
                var params = {
                    customerId: customerId,
                    type: "RECEIVER"
                };
                var title = "收货方";
                var popup = PopupManager.getLogicAddressPopup(title, params, function(recipient){
                    Ext.getCmp('recipientPanel').fillRecipientPro(recipient);
                });
            },
            listeners: {
                select: this.onRecipientSelect
            }
        }, {
            items: [{
                xtype: "hidden",
                id: "recipientId",
                name: "order.recipientId"
            }, {
                xtype: "hidden",
                id: "recipientCode",
                name: "order.recipientCode"
            }]
        }, {
            xtype: "label",
            text: "送货上门："
        }, {
            xtype: "checkbox",
            name: "order.needDelivery",
            boxLabel: " ",
            checked: true,
            inputValue: "true",
            listeners: {
                check: function(checkbox, checked){
                    if (checked) {
                        Ext.select(".recipient-add1").addClass("nodisplay");
                        Ext.getCmp("recipientPosId").disable();
                        Ext.getCmp("recipientPosName").disable();
                        Ext.select(".recipient-add2").removeClass("nodisplay");
                        Ext.getCmp("recipientAddressZoneName").enable();
                        Ext.getCmp("recipientAddressZoneId").enable();
                        Ext.getCmp("recipientAddressDetailShow").enable();
                    }
                    else {
                        Ext.select(".recipient-add1").removeClass("nodisplay");
                        Ext.getCmp("recipientPosId").enable();
                        Ext.getCmp("recipientPosName").enable();
                        Ext.select(".recipient-add2").addClass("nodisplay");
                        Ext.getCmp("recipientAddressZoneId").disable();
                        Ext.getCmp("recipientAddressZoneName").disable();
                        Ext.getCmp("recipientAddressDetailShow").disable();
                    }
                }
            }
        }, {
            xtype: "label",
            text: "卸载服务："
        }, {
            xtype: "checkbox",
            name: "order.needUnload",
            boxLabel: " ",
            inputValue: "true"
        }, {
            xtype: "label",
            text: "卸货预约："
        }, {
            xtype: "checkbox",
            id: "needDeliveryAppointment",
            name: "order.needDeliveryAppointment",
            inputValue: "true",
            boxLabel: " "
        }, {
            xtype: "label",
            text: "物流节点：",
            ctCls: "recipient-add1 nodisplay",
            cls: "requiredlabel"
        }, {
            colspan: 4,
            xtype: "popupfield",
            id: "recipientPosName",
            editable: false,
            allowBlank: true,
            width: 190,
            ctCls: "recipient-add1 nodisplay",
            popupWindow: function(){
                var popup = PopupManager.getPosPopup(function(r){
                    Ext.getCmp("recipientPosId").setValue(r.id);
                    Ext.getCmp("recipientPosName").setValue(r.name);
                });
            }
        }, {
            xtype: "hidden",
            id: "recipientAddressZoneId",
            name: "order.recipientAddressZone.id",
            ctCls: "recipient-add2"
        }, {
            xtype: "label",
            text: "详细地址：",
            ctCls: "recipient-add2",
            cls: "requiredlabel"
        }, {
            colspan: 5,
            xtype: "popupfield",
            id: "recipientAddressDetailShow",
            allowBlank: false,
            width: 250,
            ctCls: "recipient-add2",
            popupWindow: function(){
                var recipientCode = Ext.getCmp("recipientCode").getValue();
                if (!recipientCode) {
                    Ext.Msg.alert("提示", "请先选择收货方");
                    return;
                }
                var params = {
                    groupCode: recipientCode
                };
                var popup = PopupManager.getAddressPopup(params, function(r){
                    // var r = grid.getStore().getAt(rowIndex).data;
                    Ext.getCmp("recipientAddressZoneId").setValue(r.nzoneId);
                    Ext.getCmp("recipientAddressZoneName").validFlag = r.selectable;
                    Ext.getCmp("recipientAddressZoneName").setValue(r.area);
                    Ext.getCmp("recipientAddressZoneName").fireEvent("change");
                    Ext.getCmp("recipientAddressDetailShow").setValue(r.street);
                });
            },
            listeners: {
                blur: function(){
                    var address = Ext.getCmp("recipientAddressDetailShow").getValue();
                    Ext.Ajax.request({
                        url: "../../module/naturalZone/AddressParseJson.bl",
                        params: {
                            addresses: address
                        },
                        scope: this,
                        success: function(response, options){
                            var data = Ext.util.JSON.decode(response.responseText).resultList[0];
                            if (data.naturalZoneVO != null) {
                                if (data.naturalZoneVO.selectable) {
                                    Ext.getCmp("recipientAddressZoneName").clearInvalid();
                                    Ext.getCmp("recipientAddressZoneId").setValue(data.naturalZoneVO.id);
                                    Ext.getCmp("recipientAddressZoneName").validFlag = true;
                                    Ext.getCmp("recipientAddressZoneName").fireEvent("change");
                                }
                                else {
                                    Ext.getCmp("recipientAddressZoneName").markInvalid("区域无报价!");
                                    Ext.getCmp("recipientAddressZoneName").validFlag = false;
                                }
                                var address = data.naturalZoneVO.namePath.replace(/\|/g, " ");
                                var addressdetail = address + data.street;
                                Ext.getCmp("recipientAddressZoneName").setValue(address);
                                Ext.getCmp("recipientAddressDetailShow").setValue(addressdetail);
                                Ext.getCmp("recipientAddressDetail").setValue(data.street);
                            }
                        }
                    });
                }
            }
        }, {
            xtype: "label",
            text: "收货区域：",
            ctCls: "recipient-add2",
            cls: "requiredlabel"
        }, {
            colspan: 4,
            xtype: "nzonefield",
            id: "recipientAddressZoneName",
            validflag: false,
            editable: false,
            allowBlank: false,
            width: 190,
            ctCls: "recipient-add2",
            popupWindow: function(){
                Geni.Popup.showWindow({
                    url: "../../module/naturalZone/ZoneSelectable.bl",
                    title: '选择区域',
                    width: 300,
                    height: 400,
                    returnCallback: function(data){
                        Ext.getCmp("recipientAddressZoneId").setValue(data.key);
                        Ext.getCmp("recipientAddressZoneName").validFlag = true;
                        Ext.getCmp("recipientAddressZoneName").setValue(data.value);
                        Ext.getCmp("recipientAddressZoneName").fireEvent("change");
                    }
                });
            },
            listeners: {
                change: function(){
                    StoreManager.calcPodTime(Ext.getCmp('pickupDateBegain').getValue());
                }
            },
            validator: function(){
                return this.validFlag;
            }
        }, {
            items: [{
                xtype: "hidden",
                id: "recipientAddressDetail",
                name: "order.recipientAddressDetail"
            }, {
                xtype: "hidden",
                id: "recipientPosId",
                name: "order.recipientPOS.id",
                ctCls: "recipient-add1 nodisplay",
                disabled: true
            }]
        }, {
            xtype: "label",
            text: "联系人："
        }, {
            xtype: "textfield",
            id: "recipientContactPerson",
            name: "order.recipientContactPersonName",
            width: 120
        }, {
            xtype: "label",
            text: "联系电话：",
            width: 30
        }, {
            xtype: "textfield",
            id: "recipientContactPhone",
            name: "order.recipientContactPhone",
            width: 120,
            colspan: 3
        }, {
            xtype: "label",
            text: "送货时间段：",
            cls: "requiredlabel"
        }, {
            xtype: "datefield",
            vtype: "daterange",
            id: "deliveryDateBegain",
            name: "order.preferredDeliveryTimeBegain",
            allowBlank: false,
            format: "Y-m-d H:i",
            width: 130
            //endDateField: "deliveryDateEnd",
        }, {
            xtype: "label",
            text: "~"
        }, {
            xtype: "datefield",
            vtype: "daterange",
            id: "deliveryDateEnd",
            name: "order.preferredDeliveryTimeEnd",
            allowBlank: false,
            startDateField: "deliveryDateBegain",
            format: "Y-m-d H:i",
            width: 130,
            colspan: 3,
            listeners: {
                focus: function(){
                    if (Ext.getCmp("deliveryDateEnd").getValue() == null || Ext.getCmp("deliveryDateEnd").getValue() == "") {
                        Ext.getCmp("deliveryDateEnd").setValue(Ext.getCmp("deliveryDateBegain").getValue());
                    }
                }
            }
        }]
    });
}

Ext.extend(RecipientPanel, Ext.Panel, {
    fillRecipientPro: function(recipient){
        Ext.getCmp("recipientId").setValue(recipient.id);
        Ext.getCmp("recipientCode").setValue(recipient.code);
        Ext.getCmp("recipient").setValue(recipient.name);
        Ext.getCmp("needDeliveryAppointment").setValue(recipient.needReservation);
        if (recipient.defaultAddress) {
            Ext.getCmp("recipientAddressZoneId").setValue(recipient.defaultAddress.naturalZoneVO.id);
            Ext.getCmp("recipientAddressZoneName").validFlag = recipient.defaultAddress.naturalZoneVO.selectable;
            Ext.getCmp("recipientAddressZoneName").setValue(recipient.defaultAddress.area);
            Ext.getCmp("recipientAddressZoneName").fireEvent("change");
            Ext.getCmp("recipientAddressDetailShow").setValue(recipient.defaultAddress.area + recipient.defaultAddress.street);
            Ext.getCmp("recipientAddressDetail").setValue(recipient.defaultAddress.street);
            Ext.getCmp("recipientContactPerson").setValue(recipient.defaultAddress.contactPersonName);
            Ext.getCmp("recipientContactPhone").setValue(recipient.defaultAddress.contactPhone);
        }
    },
    onRecipientSelect: function(combo, record, index){
        Ext.getCmp("recipientPanel").fillRecipientPro(record.data);
    }
});

/*
 * Define ExtraInfoPanel Class
 */
ExtraInfoPanel = function(){
    var orderProWindow;
    this.vehicleTypeCategoryStore.load();
    this.vehicleTypeCategoryStore.on("load", function(store, records, options){
        var defaultVal = records[0];
        Ext.getCmp("vehicleTypeCategory").setValue(defaultVal.data.key);
    });
    ExtraInfoPanel.superclass.constructor.call(this, {
        title: "订单运输要求",
        autoHeight: true,
        frame: true,
        layout: "table",
        layoutConfig: {
            columns: 6
        },
        bodyStyle: "line-height: 26px",
        items: [{
            xtype: "label",
            id: "vehicleTypeCategoryLabel",
            text: "车辆类型：",
            cls: "formlabel"
        }, {
            xtype: "combo",
            id: "vehicleTypeCategory",
            editable: false,
            valueField: "key",
            width: 190,
            displayField: "value",
            hiddenName: "order.vehicleTypeCategory",
            store: this.vehicleTypeCategoryStore,
            forceSelection: true,
            mode: "remote",
            triggerAction: "all",
            ctCls: "formfield",
            listeners: {
                change: function(){
                    Ext.getCmp("vehicleTypeId").setValue("");
                    Ext.getCmp("vehicleTypeName").setValue("");
                },
                select: function(){
                    if (this.startValue != this.getValue()) {
                        this.fireEvent("change");
                    }
                }
            }
        }, {
            xtype: "label",
            id: "vehicleTypeLabel",
            text: "车型：",
            cls: "formlabel"
        }, {
            xtype: "popupfield",
            id: "vehicleTypeName",
            editable: false,
            width: 190,
            ctCls: "formfield",
            popupWindow: function(){
                var category = Ext.getCmp("vehicleTypeCategory").getValue();
                var params = {
                    vehicleTypeCategory: category
                };
                var popup = PopupManager.getVehicleTypePopup(params, function(r){
                    Ext.getCmp("vehicleTypeId").setValue(r.id);
                    Ext.getCmp("vehicleTypeName").setValue(r.name);
                    Ext.getCmp("vehicleTypeCategory").setValue(r.category);
                });
            }
        }, {
            xtype: "label",
            id: "routeLabel",
            text: "线路：",
            cls: "formlabel"
        }, {
            xtype: "popupfield",
            id: "routeName",
            editable: false,
            width: 190,
            ctCls: "formfield",
            popupWindow: function(){
                var customerId = Ext.getCmp("customerId").getValue();
                var senderAddressZoneId = Ext.getCmp("senderAddressZoneId").getValue();
                var recipientAddressZoneId = Ext.getCmp("recipientAddressZoneId").getValue();
                var nzoneIdStr = senderAddressZoneId + "," + recipientAddressZoneId;
                var params = {
                    customerId: customerId,
                    nzoneIdStr: nzoneIdStr
                };
                var popup = PopupManager.getRoutePopup(params, function(r){
                    Ext.getCmp("routeId").setValue(r.id);
                    Ext.getCmp("routeName").setValue(r.name);
                });
            }
        }, {
            xtype: "label",
            text: "运作组织：",
            cls: "formlabel "
        }, {
            xtype: "popupfield",
            id: "opOrgName",
            editable: false,
            allowBlank: false,
            width: 190,
            popupWindow: function(){
                Geni.Popup.showWindow({
                    url: "../../module/organization/OrganizationSelect.bl",
                    title: '选择运作组织',
                    width: 300,
                    height: 400,
                    returnCallback: function(data){
                        Ext.getCmp("opOrgId").setValue(data.key);
                        Ext.getCmp("opOrgName").setValue(data.value);
                    }
                });
            }
        }, {
            xtype: "label",
            text: "订单重要度：",
            cls: "formlabel"
        }, {
            xtype: "combo",
            colspan: 4,
            id: "saleOrderWeightnessLevel",
            editable: false,
            valueField: "weightness",
            value: "NORMAL",
            width: 190,
            displayField: "displayText",
            mode: 'local',
            hiddenName: 'order.weightnessLevel',
            autoSelect: true,
            triggerAction: 'all',
            selectOnFocus: false,
            store: new Ext.data.ArrayStore({
                fields: ['weightness', 'displayText'],
                data: [['NORMAL', '普通'], ['HIGH', '高']]
            })
        }, {
            xtype: "label",
            text: "订单属性:",
            cls: "formlabel"
        }, {
            colspan: 5,
            layout: "column",
            items: [{
                xtype: "button",
                iconCls: "silk-add",
                listeners: {
                    click: function(){
                        var orderProConfig;
                        if (!orderProWindow) {
                            var checkboxitems = [];
                            Ext.Ajax.request({
                                url: "../../popup/extjs/GetOrderPros.bl",
                                scope: this,
                                success: function(response, options){
                                    var datas = (Ext.util.JSON.decode(response.responseText))[4].orderPro;
                                    Ext.each(datas, function(data){
                                        var option = {};
                                        option.xtype = "checkbox";
                                        option.boxLabel = data.defaultDescription;
                                        option.name = data.defaultDescription;
                                        option.id = data.code;
                                        var checkbox = new Ext.form.Checkbox(option);
                                        checkboxitems.push(checkbox);
                                    });
                                    orderProWindow = new Ext.Window({
                                        title: "订单属性",
                                        id: "orderProWindow",
                                        width: 500,
                                        autoHeight: true,
                                        buttonAlign: "left",
                                        closeAction: "hide",
                                        items: new Ext.form.CheckboxGroup({
                                            id: 'orderProGroup',
                                            fieldLabel: 'Single Column',
                                            itemCls: 'x-check-group-alt',
                                            dafaultType: "checkbox",
                                            height: 200,
                                            allowBlank: true,
                                            // Put all controls in a single column with width 100%
                                            columns: 5,
                                            items: checkboxitems
                                        }),
                                        buttons: [{
                                            text: "确定",
                                            scope: this,
                                            handler: function(){
                                                var propObjectArray = Ext.getCmp("orderProGroup").getValue();
                                                var propStrArray = [];
                                                var propStr;
                                                Ext.each(propObjectArray, function(prop){
                                                    propStrArray.push(prop.name);
                                                });
                                                propStr = propStrArray.join(' ');
                                                Ext.getCmp('orderProperties').setValue(propStr);
                                                Ext.get("orderProShow").child("span").remove();
                                                Ext.get("orderProShow").insertHtml("beforeEnd", "<span>" + propStr + "</span>");
                                                orderProWindow.hide();
                                            }
                                        }]
                                    });
                                    var orderPro = Ext.getCmp("orderProperties").getValue().split(' ');
                                    if (orderPro.length > 0) {
                                        orderProConfig = {};
                                        for (var i = 0; i < orderPro.length; i++) {
                                            orderProConfig[orderPro[i]] = true;
                                        }
                                    }
                                    Ext.getCmp('orderProGroup').reset();
                                    Ext.getCmp('orderProGroup').setValue(orderProConfig);
                                    orderProWindow.show();
                                }
                            });
                        }
                        if (orderProWindow) {
                            var orderPro = Ext.getCmp("orderProperties").getValue().split(' ');
                            if (orderPro.length > 0) {
                                orderProConfig = {};
                                for (var i = 0; i < orderPro.length; i++) {
                                    orderProConfig[orderPro[i]] = true;
                                }
                            }
                            Ext.getCmp('orderProGroup').reset();
                            Ext.getCmp('orderProGroup').setValue(orderProConfig);
                            orderProWindow.show();
                        };
                                            }
                }
            }, {
                xtype: "label",
                id: 'orderProShow',
                cls: "formlabel",
                // colspan: 4,
                html: "<span></span>"
            }]
        }, {
            xtype: "label",
            text: "特殊运作要求:",
            cls: "formlabel"
        }, {
            xtype: "textfield",
            id: "specialRequirement",
            name: "order.specialReqirement",
            width: 400,
            colspan: 4
        }, {
            items: [{
                xtype: "hidden",
                id: "vehicleTypeId",
                name: "order.vehicleType.id"
            }, {
                xtype: "hidden",
                id: "routeId",
                name: "order.route.id"
            }, {
                xtype: "hidden",
                id: "opOrgId",
                name: "order.opOrg.id"
            }, {
                xtype: "hidden",
                id: "routeId",
                name: "order.route.id"
            }, {
                xtype: "hidden",
                id: "orderProperties",
                name: "order.orderProperties"
            }]
        }]
    });
}
Ext.extend(ExtraInfoPanel, Ext.Panel, {
    vehicleTypeCategoryStore: StoreManager.getVehicleTypeCategoryStore(true)
});

/*
 * Define SoItemsPanel Class
 */
Ext.util.Format.comboRenderer = function(combo){
    return function(value){
        var record = combo.findRecord(combo.valueField, value);
        return record ? record.get(combo.displayField) : combo.valueNotFoundText;
    }
}
SoItemsPanel = function(){
    this.dataStore = new Ext.data.ArrayStore({
        fields: [{
            name: "freightId"
        }, {
            name: "freightCode"
        }, {
            name: "freightName"
        }, {
            name: "packingId"
        }, {
            name: "packingCode"
        }, {
            name: "packingModeId"
        }, {
            name: "packingModeDesc"
        }, {
            name: "packingSpecAmount"
        }, {
            name: "packingSpecUnit"
        }, {
            name: "amount",
            type: "int"
        }, {
            name: "weight",
            type: "float"
        }, {
            name: "volume",
            type: "float"
        }, {
            name: "fvalue",
            type: "float"
        }, {
            name: "businessAssociatedId"
        }, {
            name: "businessAssociatedName"
        }, {
            name: "bizNumber"
        }, {
            name: "desc"
        }],
        listeners: {
            update: function(store, record, operation){
            
            }
        }
    });
    
    var columns = [{
        header: "货物",
        dataIndex: "freightName",
        width: 120,
        sortable: true
    }, {
        header: "包装",
        dataIndex: "packingModeDesc",
        width: 80,
        sortable: true
    }, {
        header: "数量",
        dataIndex: "amount",
        width: 60,
        sortable: true,
        align: "right"
    }, {
        header: "重量",
        dataIndex: "weight",
        width: 60,
        sortable: true,
        align: "right"
    }, {
        header: "体积",
        dataIndex: "volume",
        width: 60,
        sortable: true,
        align: "right"
    }, {
        header: "货值",
        dataIndex: "fvalue",
        width: 60,
        sortable: true,
        align: "right"
    }, {
        header: "业务关联方",
        dataIndex: "businessAssociatedName",
        width: 100,
        sortable: true,
        align: "right"
    }, {
        header: "业务单号",
        dataIndex: "bizNumber",
        width: 100
    }, {
        header: "备注",
        id: "descCol",
        dataIndex: "desc",
        width: 100
    }];
    
    SoItemsPanel.superclass.constructor.call(this, {
        id: "soiPanel",
        title: "货物信息",
        frame: true,
        // plugins: [editor],
        height: 180,
        stripeRows: true,
        store: this.dataStore,
        autoExpandColumn: "descCol",
        columns: columns,
        tbar: [{
            text: "增加货物",
            iconCls: "silk-add",
            scope: this,
            handler: function(){
                var soiWindow = new SoiWindow();
                soiWindow.setTitle(Ext.getCmp('settlementtype').getValue());
                soiWindow.show();
                var freightStore = Ext.getCmp("freightName").store;
                freightStore.baseParams = {
                    customerId: Ext.getCmp("customerId").getValue()
                }
            }
        }, "-", {
            text: "修改货物",
            iconCls: "silk-update",
            scope: this,
            handler: function(){
                var grid = Ext.getCmp("soiPanel");
                var r = grid.getSelectionModel().getSelected();
                if (r) {
                    var soiWindow = new SoiWindow(r);
                    soiWindow.setTitle(Ext.getCmp('settlementtype').getValue());
                    soiWindow.show();
                }
            }
        }, "-", {
            text: "删除货物",
            iconCls: "silk-delete",
            handler: function(){
                var grid = Ext.getCmp("soiPanel");
                var s = grid.getSelectionModel().getSelections();
                for (var i = 0, r; r = s[i]; i++) {
                    if (r.data.id) {
                        grid.toBeDelSoiIds.push(r.data.id);
                    }
                    grid.dataStore.remove(r);
                }
            }
        }, "-"],
        
        listeners: {
            rowdblclick: function(){
                var grid = Ext.getCmp("soiPanel");
                var r = grid.getSelectionModel().getSelected();
                var soiWindow = new SoiWindow(r);
                soiWindow.setTitle(Ext.getCmp('settlementtype').getValue());
                soiWindow.show();
            }
        }
    });
    
}
Ext.extend(SoItemsPanel, Ext.grid.GridPanel, {
    freightStore: StoreManager.getFreightStore(),
    packingStore: StoreManager.getPackingStore(),
    bizAssociatedStore: StoreManager.getBizAssociatedStore()
});

